<?php
include ("../Action/config.php");
include ("./gcm_message_sender.php");

//first, get all of text from cilent.
$data = file_get_contents("php://input");
//second, decode data from client because it is encoded through UTF-8
$urldecode_data = urldecode($data);
//third, decode one more time to json type
$array_data = json_decode($urldecode_data, true);

$child_num = $array_data['child_num'];
$app_info_arr = array();
$app_info_arr = $array_data['app_info'];

foreach($app_info_arr as $app_info){
	//get app info data
	$app_name = $app_info['app_name'];
	$package_name = $app_info['package_name'];
	$forbidden = $app_info['forbidden'];
	
	//query 
	$sql = "UPDATE APP_INFO SET forbidden='$forbidden' 
		WHERE package_name = '$package_name' and child_num= '$child_num'";
	$result = mysql_query($sql);	
}

// $file = $_SERVER['DOCUMENT_ROOT']
// .'/SBWebServer/ForbiddenApplistDB/['.$parent_num.']_applist.txt'; 
// [child_num]_applist.txt 로 저장한다.

//convert Array to JSON
// $json_app_list = json_encode($app_info_arr);

//finally, save file and send it.
// file_put_contents($file, $json_app_list);

//send GCM message to children
$message = "ANDROID_FORBIDDEN";
sendGcmMessage($message, $child_num);

echo $json_app_list;
exit();
?>